package com.nanyang.tms.service.waybill.impl.flow;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.nanyang.common.core.flow.context.TransHandlerContext;
import com.nanyang.common.core.flow.convert.TransConvert;
import com.nanyang.common.core.flow.factory.AbstranctTransPipelineFactory;
import com.nanyang.common.core.flow.invoker.DefaultTransPipeline;
import com.nanyang.common.core.flow.invoker.TransPipeline;
import com.nanyang.tms.api.dto.request.waybill.WaybillAddReuqest;
import com.nanyang.tms.domain.waybill.context.WaybillAddContext;
import com.nanyang.tms.manager.forecast.handler.CalculateFreightHandler;
import com.nanyang.tms.manager.forecast.handler.CalculateWeightHandler;
import com.nanyang.tms.manager.waybill.handler.CutPaymentHandler;
import com.nanyang.tms.manager.waybill.handler.SaveIncomeHandler;
import com.nanyang.tms.manager.waybill.handler.SaveTackInfoHandler;
import com.nanyang.tms.manager.waybill.handler.SaveWaybillReceiptHandler;
import com.nanyang.tms.manager.waybill.handler.UpdateForecastHandler;
import com.nanyang.tms.manager.waybill.handler.UpdateReceiptHandler;
@Component
public class WaybillProcessPipelineFactory extends AbstranctTransPipelineFactory<WaybillAddReuqest>{
	@Autowired
	private  CalculateWeightHandler calculateWeightHander;
	@Autowired
	private CalculateFreightHandler calculateFreightHandler;
	@Autowired
	private UpdateReceiptHandler updateReceiptHandler;
	@Autowired
	private UpdateForecastHandler updateForecastHandler;
	@Autowired
	private SaveWaybillReceiptHandler saveWaybillReceiptHandler;
	@Autowired
	private CutPaymentHandler  cutPaymentHandler;
	@Autowired
	private SaveIncomeHandler saveIncomeHandler;
	@Autowired
	private SaveTackInfoHandler saveTackInfoHandler;
	@Override
	public TransHandlerContext createContext() {
		return new WaybillAddContext();
	}

	@Override
	public void doBuild(TransPipeline pipeline) {
		pipeline.addLast(calculateWeightHander);//计算重量
		pipeline.addLast(calculateFreightHandler);//计算运费
		pipeline.addLast(false,saveWaybillReceiptHandler);//保存运单及更新收货材积信息
		pipeline.addLast(false,updateReceiptHandler);//更新收货单
		pipeline.addLast(false,updateForecastHandler);//更新预报单
		pipeline.addLast(false,cutPaymentHandler);//扣款并生成动账记录
		pipeline.addLast(false,saveIncomeHandler);//保存收入信息
		pipeline.addLast(true,saveTackInfoHandler);//保存轨迹信息
		
	}

	@Override
	public TransPipeline createPipeline(TransHandlerContext context) {
		return new DefaultTransPipeline(context,super.getDataSourceTransactionManager(),super.getTransactionDefinition()); 
	}

	@Override
	public TransConvert createConvert() {
		return new WaybillConvert();
	}

}
